<?php
class Excel {
	private $sContent;
	private $sPseudoname = "SomeProject.xls";

	public function Excel($oJob) {
		loadLib('writeexcel');

		$sMissiongroups = $oJob->getMissiongroups();
		$oMissions = $oJob->getMissions();

		$sFilename = tempnam('/tmp', 'mijob.temp.xls');

		$oBook =& new writeexcel_workbook($sFilename);
		$oSheet =& $oBook->addworksheet('Demo');
		$oSheet->set_column('A:B', 32);

		$oHeaderStyle =& $oBook->addformat(
			array(
				bold => 1,
				//color => 'blue',
				size => 18,
				merge => 1,
				bottom => 50,
			)
		);

		$sHeadingsText = array('Features of php_writeexcel', '');
		$oSheet->write_row('A1', $sHeadingsText, $oHeaderStyle);

		$iRow = 2;
		foreach ($sMissiongroups as $iGroup => $sThisGroup) {
			$oSheet->write_row('A'.$iRow, array($sThisGroup));
			$iRow++;
			foreach ($oMissions as $oThisMission) {
				if ($oThisMission->iGroup == $iGroup) {
					$oSheet->write_row('B'.$iRow, array($oThisMission->sTodo));
					$iRow++;
				}
			}
		}
		$oBook->close();

		$this->sContent = '';
		$oFile = fopen($sFilename, 'r');
		while ($sLine = fgets($oFile)) {
			$this->sContent .= $sLine;
		}
		fclose($oFile);
		unlink($sFilename);
	}

	public function getFilename() {
		return $this->sPseudoname;
	}

	public function toString() {
		return $this->sContent;
	}
}
?>
